package com.ylc.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylc.reggie.common.CustomException;
import com.ylc.reggie.common.R;
import com.ylc.reggie.entity.SetmealDish;
import com.ylc.reggie.mapper.SetmealDishMapper;
import com.ylc.reggie.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ylc
 * @Description:
 */
@Service
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish> implements SetmealDishService {
    @Autowired
    private SetmealDishService setmealDishService;

    @Override
    public List<SetmealDish> listDishId(List<Long> ids) {
        LambdaQueryWrapper<SetmealDish> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SetmealDish::getDishId, ids);
        List<SetmealDish> setmealDishes = setmealDishService.listByIds(ids);
        return setmealDishes;
    }

    @Override
    public boolean getDishInSetmeal(List<Long> ids) {
        LambdaQueryWrapper<SetmealDish> queryWrapperSM = new LambdaQueryWrapper<>();
        boolean flag = true;
        queryWrapperSM.in(SetmealDish::getDishId, ids);
        int count = setmealDishService.count(queryWrapperSM);
        if(count > 0){
            flag = false;
        }
        return flag;
    }
}
